/**
 * Project Name:mauto-web
 * File Name:AreaService.java
 * Package Name:com.inftech.mauto.sys.service
 * Date:2016年10月7日下午9:14:13
 * Copyright (c) 2016, inf-technology Co., Ltd. All Rights Reserved.
 *
*/

package com.inftech.mauto.sys.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.inftech.mauto.sys.dao.IGoodsDao;
import com.inftech.mauto.sys.entity.Goods;
import com.mingsoft.base.biz.impl.BaseBizImpl;
import com.mingsoft.base.dao.IBaseDao;

/**
 * ClassName:GoodsService <br/>
 * Function: 商品业务service. <br/>
 * Date: 2016年10月7日 下午9:14:13 <br/>
 * 
 * @author puyf
 * @version
 * @since JDK 1.7
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Service("goodsService")
public class GoodsService extends BaseBizImpl {

	/**
	 * 服务单位持久化层注入
	 */
	@Autowired
	private IGoodsDao goodsDao;

	@Override
	protected IBaseDao getDao() {
		return goodsDao;
	}

	/**
	 * 
	 * queryGoodsList:查询商品列表. <br/>
	 *
	 * @author puyf
	 * @param carPrice
	 * @return
	 * @throws Exception
	 * @since JDK 1.7
	 */
	public Map<String, Map<String, List<Map<String, Object>>>> queryGoodsList(Map<String, Object> paramMap)
			throws Exception {
		// 获取商品列表
		List<Goods> goodsList = goodsDao.queryGoodsList(paramMap);
		// 返回map
		Map<String, Map<String, List<Map<String, Object>>>> resultMap = new HashMap<String, Map<String, List<Map<String, Object>>>>();
		if (goodsList != null && goodsList.size() != 0) {
			for (Goods goods : goodsList) {
				// 位置
				Integer carLocationId = goods.getCarLocationId();
				String carLocationName = goods.getCarLocationName();
				String carLocation = carLocationId + "-" + carLocationName;
				// 钣喷类型
				String bpType = goods.getBpType();
				Map<String, Object> goodsM = new HashMap<String, Object>();
				// 商品编码
				goodsM.put("goodsCode", goods.getGoodsCode());
				// 商品价格
				goodsM.put("goodsPrice", goods.getGoodsPrice());
				// 项目名称
				goodsM.put("bpItem", goods.getBpItem());
				// 获取位置对应的map
				Map<String, List<Map<String, Object>>> locationMap = resultMap.get(carLocation);
				if (locationMap == null) {
					locationMap = new HashMap<String, List<Map<String, Object>>>();
				}
				// 获取钣喷类型对应的map
				List<Map<String, Object>> gMapList = locationMap.get(bpType);
				if (gMapList == null) {
					gMapList = new ArrayList<Map<String, Object>>();
				}
				gMapList.add(goodsM);
				if (gMapList.size() == 1) {
					locationMap.put(bpType, gMapList);
					resultMap.put(carLocation, locationMap);
				}
			}
		}
		return resultMap;
	}

	/**
	 * 
	 * queryGoodsPrice:获取商品价格. <br/>
	 *
	 * @author puyf
	 * @param paramMap
	 * @return
	 * @throws Exception
	 * @since JDK 1.7
	 */
	public BigDecimal queryGoodsPrice(Map<String, Object> paramMap) throws Exception {
		// 获取商品列表
		paramMap.put("goodsCodes", ((String) paramMap.get("goodsCodes")).split(","));
		List<Goods> goodsList = goodsDao.queryGoodsList(paramMap);
		BigDecimal price = new BigDecimal("0.00");
		if (goodsList != null && goodsList.size() != 0) {
			for (Goods goods : goodsList) {
				price = price.add(goods.getGoodsPrice());
			}
		}
		return price;
	}
}
